<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            position: relative;
            background: url(images/pckbd.png) no-repeat;
            width: 1315px;
            height: 511px;
            margin: 100px auto;
        }

        .c1 {
            position: absolute;
            background: rgba(155, 155, 155, 0.5);
        }

        .c2 {
            background: rgba(70, 248, 0, 0.6);
        }
    </style>
</head>

<body>
    <div class="keyboard">
        <!-- <div class="c"></div> -->
    </div>
    <script>
        var keyboard = document.querySelector('.keyboard');
        // console.log(keyboard);
        document.addEventListener('keydown', function (e) {
            // e.preventDefault();
            var d = document.createElement('div');
            d.className = ('c1 c2');
            d.style.left = '1070px';
            d.style.top = '184px';
            d.style.width = '49px';
            d.style.height = '60px';

            keyboard.appendChild(d);
            console.log(e.keyCode);
        })
    </script>
</body>

</html>